#include "./widgets/mainwindow.h"

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QDir>

#include "./entities/messageentities.h"



int main(int argc, char *argv[])
{

    // 注册自定义类型
    qRegisterMetaType<LoginRequestMessage>("LoginRequestMessage");
    qRegisterMetaType<LoginResponseMessage>("LoginResponseMessage");
    qRegisterMetaType<RegisterRequestMessage>("RegisterRequestMessage");
    qRegisterMetaType<RegisterResponseMessage>("RegisterResponseMessage");
    qRegisterMetaType<LogoutRequestMessage>("LogoutRequestMessage");
    qRegisterMetaType<LogoutResponseMessage>("LogoutResponseMessage");
    qRegisterMetaType<SearchUserRequestMessage>("SearchUserRequestMessage");
    qRegisterMetaType<SearchUserResponseMessage>("SearchUserResponseMessage");
    qRegisterMetaType<ApplyFriendRequestMessageToServer>("ApplyFriendRequestMessageToServer");
    qRegisterMetaType<ApplyFriendRequestMessageToClient>("ApplyFriendRequestMessageToClient");
    qRegisterMetaType<ApplyFriendResponseMessageToServer>("ApplyFriendResponseMessageToServer");
    qRegisterMetaType<ApplyFriendResponseMessageToClient>("ApplyFriendResponseMessageToClient");
    qRegisterMetaType<GetApplicationFromServer>("GetApplicationFromServer");
    qRegisterMetaType<GetApplicationResultFromServer>("GetApplicationResultFromServer");
    qRegisterMetaType<RequestBufferDataMessage>("RequestBufferDataMessage");
    qRegisterMetaType<ChatMessageToServer>("ChatMessageToServer");
    qRegisterMetaType<ChatMessageToClient>("ChatMessageToClient");
    qRegisterMetaType<GetChatMessageFromServer>("GetChatMessageFromServer");
    qRegisterMetaType<VideoRequestToServer>("VideoRequestToServer");
    qRegisterMetaType<VideoRequestToClient>("VideoRequestToClient");
    qRegisterMetaType<VideoResponseToServer>("VideoResponseToServer");
    qRegisterMetaType<VideoRequestToClient>("VideoRequestToClient");
    qRegisterMetaType<VideoCallFinished>("VideoCallFinished");


    QApplication a(argc, argv);


    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "XyChatServer_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }
    MainWindow w;
    w.show();
    return a.exec();
}
